﻿using System.Web.UI;
using System.Web.UI.WebControls;
using Ue.Framework.Web.WebControls;
using Ue.Infrastructure.Web.UI;
using Ue.Qcdz.Domain.Products;
namespace Ue.Qcdz.UI.Controls.Products
{
    public class ProductEdit : SkinnedEntityEdit<Product>
    {
        private string skinFileName = "~/Admin/Themes/Skins/Products/ProductEdit.ascx";
        private TextBox tbxProductTitle;
        private TextBox tbxProductImageUrl;
        private TextBox tbxProductLink;
        private StateRadio stateRadio;
        #region Overrides of SkinnedControl

        protected override string GetSkinFileName()
        {
            return skinFileName;
        }

        #endregion

        #region Overrides of SkinnedEntityEdit<Product>

        protected override void InitSkin(Control skin)
        {
            tbxProductTitle = skin.FindControl<TextBox>("tbxProductTitle");
            tbxProductImageUrl = skin.FindControl<TextBox>("tbxProductImageUrl");
            tbxProductLink = skin.FindControl<TextBox>("tbxProductLink");
            stateRadio = skin.FindControl<StateRadio>("stateRadio");
        }

        protected override Product Enttiy
        {
            get
            {
                if(this.Action=="Delete")
                {
                    return new Product(this.EntityKey);
                }
                return new Product(
                    tbxProductTitle.GetValue<string>(),
                    tbxProductImageUrl.GetValue<string>(),
                    tbxProductLink.GetValue<string>(),
                    stateRadio.SelectedValue,
                    this.EntityKey
                    );
            }
            set
            {
                if(value==null)
                    return; 
                tbxProductTitle.SetValue(value.ProductTitle);
                tbxProductLink.SetValue(value.ProductLink);
                tbxProductImageUrl.SetValue(value.ProductImageUrl);
                stateRadio.SelectedValue = value.State;
            }
        }

        #endregion
    }
}
